import 'package:flutter/material.dart';

/// 2022年更新  适配 flutter 3.0
class Material3Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return Material3HomeState();
  }
}

class Material3HomeState extends State {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Material3"),
      ),
      backgroundColor: Colors.grey,
      body: SizedBox.expand(
        child: Column(
          children: [buildMaterial()],
          mainAxisAlignment: MainAxisAlignment.center,
        ),
      ),
    );
  }

  Widget buildMaterial() {
    ///当前颜色主题
    ColorScheme colorScheme = Theme.of(context).colorScheme;
    //背景色
    final Color color = colorScheme.surface;
    //阴影色
    Color shadowColor = colorScheme.shadow;
    Color surfaceTint = colorScheme.primary;
    return Material(
      borderRadius: BorderRadius.all(Radius.circular(4.0)),
      elevation: 4,//阴影
      color: color,//背景色
      shadowColor: shadowColor,//阴影色
      surfaceTintColor: surfaceTint,//
      type: MaterialType.card,
      child: Padding(
        padding: const EdgeInsets.all(38.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text(
              '测试1',
              style: Theme.of(context).textTheme.labelMedium,
            ),
            Text(
              '测试2',
              style: Theme.of(context).textTheme.labelMedium,
            ),
          ],
        ),
      ),
    );
  }

  Widget buildFloatButton() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        FloatingActionButton.small(
          onPressed: () {},
          child: const Icon(Icons.add),
        ),
        SizedBox(height: 22),
        FloatingActionButton(
          onPressed: () {},
          child: const Icon(Icons.add),
        ),
        SizedBox(height: 22),
        FloatingActionButton.extended(
          onPressed: () {},
          icon: const Icon(Icons.add),
          label: const Text("Create"),
        ),
        SizedBox(height: 22),
        FloatingActionButton.large(
          onPressed: () {},
          child: const Icon(Icons.add),
        ),
      ],
    );
  }

  Widget buildButton() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        ElevatedButton(
          onPressed: () {},
          child: const Text("Elevated"),
        ),
        SizedBox(height: 22),
        ElevatedButton(
          style: ElevatedButton.styleFrom(
            // Foreground color
            // ignore: deprecated_member_use
            onPrimary: Theme.of(context).colorScheme.onPrimary,
            // Background color
            // ignore: deprecated_member_use
            primary: Theme.of(context).colorScheme.primary,
          ).copyWith(elevation: ButtonStyleButton.allOrNull(0.0)),
          onPressed: () {},
          child: const Text('Filled'),
        ),
        SizedBox(height: 22),
        ElevatedButton(
          style: ElevatedButton.styleFrom(
            // Foreground color
            // ignore: deprecated_member_use
            onPrimary: Theme.of(context).colorScheme.onSecondaryContainer,
            // Background color
            // ignore: deprecated_member_use
            primary: Theme.of(context).colorScheme.secondaryContainer,
          ).copyWith(elevation: ButtonStyleButton.allOrNull(0.0)),
          onPressed: () {},
          child: const Text('Filled Tonal'),
        ),
        SizedBox(height: 22),
        OutlinedButton(
          onPressed: () {},
          child: const Text("Outlined"),
        ),
      ],
    );
  }
}
